#ifndef SHOW3D_H
#define SHOW3D_H

#include <QWidget>
#include <QKeyEvent>
#include <QPaintEvent>
#include <QMouseEvent>
#include <QPainter>
#include <QPen>
#include <QImage>
#include <QDebug>
#include <QTimer>
#include <QPoint>

#include <vector>
#include <iostream>
using namespace std;


typedef struct
{
    double x;
    double y;
    double z;
    int c;
}POINT3D;

typedef struct
{
    double x;
    double y;
}POINT;

namespace Ui {
class show3d;
}

class show3d : public QWidget
{
    Q_OBJECT

public:
    explicit show3d(QWidget *parent = 0);
    ~show3d();



    void keyPressEvent(QKeyEvent *ev);
    void paintEvent(QPaintEvent *);

    void RotateX(POINT3D &p, double angle);
    void RotateY(POINT3D &p, double angle);
    void RotateZ(POINT3D &p, double angle);
    POINT Projection(POINT3D p);

    void init(int max_size)
    {
        p3d=(POINT3D *)malloc(sizeof(POINT3D)*max_size);
        point_num=0;

        _angle_x = 0;
        _angle_y = 0;
        _angle_z = 0;
        viewZ=3;
        rate=1;
        pen_width=1;
        //rate_color=1;
    }

    void getPoints(unsigned char **data, int w, int h)
    {
        init((w+1)*(h+1));
        for(int i=0;i<w;i++)
        {
            for(int j=0;j<h;j++)
            {
                if(data[i][j]!=0)
                {
                    p3d[point_num].x=(1.0*i-w*0.5)/(w*0.5);
                    p3d[point_num].y=(1.0*j-h*0.5)/(h*0.5);
                    p3d[point_num].z=(1.0*data[i][j]-128)/128.0;
                    p3d[point_num].c=data[i][j];
                    point_num++;
                }
            }
        }
    }

    POINT3D *p3d;
    int point_num;

    double _angle_x;
    double _angle_y;
    double _angle_z;

    double viewZ;

    double rate;
    int pen_width;


private:
    Ui::show3d *ui;
};

#endif // SHOW3D_H
